<template>
    <div class="container">
        <div class="handle-box">
                <el-form ref="form" :model="form" label-width="90px" class="flex">
                    <el-form-item label="社区名称：">
                        <el-input v-model="name" placeholder="请输入名称" class="handle-input mr10" @input="mohu()"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                        <!-- <el-button type="success" icon="el-icon-circle-plus-outline" @click="addvialog()">新增</el-button> -->
                    </el-form-item>
                    
                </el-form>
            </div>
            <el-table
                :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
            >
                <el-table-column prop="COMMUNITY_ID" label="ID" width="55" align="center"></el-table-column>
                <el-table-column prop="STREET_NAME" label="所属街道"></el-table-column>
                <el-table-column prop="COMMUNITY_NAME" label="社区名称"></el-table-column>
                <el-table-column prop="totalintegral" label="累计积分">
                    <template scope="scope">
                        <div class="u" @click="getMore(scope.row)">{{ scope.row.TotalPoints }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="totalscore" label="消费积分">
                    <template scope="scope">
                        <div class="u" @click="getscoreMore(scope.row)">{{ scope.row.ConsumePoints }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="SurplusPoints" label="剩余积分"></el-table-column>
                <!-- <el-table-column label="垃圾分类">
                    <template slot-scope="scope">￥{{scope.row.money}}</template>
                </el-table-column>
                <el-table-column prop="address" label="积分类型"></el-table-column>
                <el-table-column label="状态" align="center">
                    <template slot-scope="scope">
                        <el-tag
                            :type="scope.row.state==='成功'?'success':(scope.row.state==='失败'?'danger':'')"
                        >{{scope.row.state}}</el-tag>
                    </template>
                </el-table-column>

                <el-table-column prop="date" label="分数规则(分)"></el-table-column> -->
                <!-- <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index, scope.row)"
                        >详情</el-button>
                    </template>
                </el-table-column> -->
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page="currentPage"  
                    :page-size="pageSize"
                    :total="tableData.length"
                    @size-change="handleSizeChange"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
            <!-- 编辑弹出框 -->
            <el-dialog v-dialogDrag title="详情" :visible.sync="editVisible" width="30%" >
                <el-form ref="form" :model="form" label-width="70px" class="diaglos display">
                    <el-form-item label="所属街道：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.address" class="inputstyle" type="text" disabled="disabled" ></input>
                    </el-form-item>
                    <el-form-item label="社区名称：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.community" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item>
                    <!-- <el-form-item label="日期范围：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.date" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item> -->
                    <!-- <el-form-item label="可回收垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.integral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item> -->
                    <!-- <el-form-item label="可回收垃圾消费积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.score"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="可回收垃圾剩余积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.remaining"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="厨余垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.chuyuintegral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item> -->
                    <!-- <el-form-item label="厨余垃圾消费积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.chuyuscore"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="厨余垃圾剩余积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.chuyuremaining"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="有害垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.youhaiintegral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item>  -->
                    <!-- <el-form-item label="有害垃圾消费积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.youhaiscore"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="有害垃圾剩余积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.youhairemaining"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="其他垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.qitaintegral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item>  -->
                    <!-- <el-form-item label="其他垃圾消费积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.qitascore"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="其他垃圾剩余积分：" :label-width="formLabelWidth">
                        <el-input v-model="form.qitaremaining"></el-input>
                    </el-form-item> -->
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="editVisible = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit">确 定</el-button>
                </span>
            </el-dialog>
                <!-- 累计积分明细 -->
             <el-dialog v-dialogDrag title="累计积分明细" :visible.sync="getmoredialog" width="50%" >
                 <el-table :data="communitydetaildata">
                    <el-table-column prop="VILLAGE_ID" label="社区ID"  align="center"></el-table-column>
                    <el-table-column prop="VILLAGE_NAME" label="社区名称"></el-table-column>
                    <el-table-column prop="Points" label="积分"></el-table-column>
                </el-table>
            </el-dialog>
            <!-- 消费积分明细 -->
             <el-dialog v-dialogDrag title="消费积分明细" :visible.sync="getscoremoredialog" width="50%" >
                 <el-table :data="communityildata">
                    <el-table-column prop="VILLAGE_ID" label="社区ID"  align="center"></el-table-column>
                    <el-table-column prop="VILLAGE_NAME" label="社区名称"></el-table-column>
                    <el-table-column prop="Points" label="积分"></el-table-column>
                </el-table>
            </el-dialog>
            <!-- 新增弹出框 -->
             <el-dialog v-dialogDrag title="新增" :visible.sync="adddatevialog" width="50%" >
                 <el-form ref="addform" :model="addform" label-width="70px" class="diaglos display">
                    <el-form-item label="社区名称：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.address" ></el-input>
                    </el-form-item>
                    <el-form-item label="社区累计积分：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.totalintegral"></el-input>
                    </el-form-item>
                    <el-form-item label="社区消费积分：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.totalscore"></el-input>
                    </el-form-item>
                    <el-form-item label="社区剩余积分：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.totalremaining"></el-input>
                    </el-form-item> 
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="adddatevialog = false">取 消</el-button>
                    <el-button type="primary" @click="saveEditvialog">确 定</el-button>
                </span>
            </el-dialog>
        </div>
</template>
<script>
import '../../../assets/css/common.css'

export default {
    data(){
        return{
              currentPage:1, //初始页
                pagesize:10,    //    每页的数据
                userList: [],
                address:'',
                name:'',
                value1: '',
                formLabelWidth:'160px',
                getmoredialog:false,
                getscoremoredialog:false,
                addform:{
                    address:'',
                    totalintegral:'',
                    totalscore:'',
                    totalremaining:''
                },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1,
            communitydetail:[{
                index:'1',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communityname:'丽华里社区',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]
            },{
                index:'2',
               communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]              
            },{
                index:'3',
               communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]            
            },{
                index:'4',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]               
            },{
                index:'5',
               communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]              
            },{
                index:'6',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]               
            },{
                index: '7',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]               
            },{
                index:'8',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]                
            },{
                index:'9',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]                
            },{
                index:'10',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]                
            },{
                index:'11',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]               
            },{
                index:'12',
                communname:[{
                    streename: '华苑街道',
                    plotname:'丽华里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '梅苑街道',
                    plotname:'科信里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },{
                    streename: '美元街道',
                    plotname:'荻花里',
                    communtonnage: '80',
                    communityname:'丽华里社区',
                },]                
            }],
            communitydetaildata:'',
            communityildata: '',
            adddatevialog:false,
        }
    },
    created() {
        this.getdata();
    },
    methods: {
        getdata(){
        //    const { data } =await this.$axios.get(this.$iurl+'/GetCommunityIntegralListApi')
            // this.tableData = data.filter(item=>{
            //     return item 
            // })
            this.$axios({
                url: this.$iurl + '/GetCommunityIntegralListApi',
                method: 'get',
                params: {
                    ClientNo: localStorage.getItem('clentno')
                }
            }).then(res=>{
                // console.log(res.data)
                this.tableData = Object.assign([],res.data)
            })
        },
        async saveEditvialog(){
            this.adddatevialog = false
        },
        //新增弹出框
        async addvialog(){
            this.adddatevialog = true
        },
        //累计积分弹框
        async getMore(row){
           this.$axios({
                url: this.$iurl+'/GetCommunityCumulativeIntegralDetailApi',
                method: 'get',
                params:{
                    COMMUNITY_ID: row.COMMUNITY_ID
                }
            }).then(item=>{
               if(item.status == 200){
                   console.log(item.data)
                   this.communitydetaildata = Object.assign([],item.data)
               }
                
            })
            this.getmoredialog = true
        },
         //消费积分弹框
        async getscoreMore(row){
              this.$axios({
                url: this.$iurl+'/GetCommunityConsumptionPointsDetailApi',
                method: 'get',
                params:{
                    COMMUNITY_ID: row.COMMUNITY_ID
                }
            }).then(item=>{
               if(item.status == 200){
                   if(item.data == ''){
                       document.querySelector('.p').style.display ='block';
                       document.querySelector('.table').style.display = 'none'
                   }else{
                        console.log(item.data)
                        this.communityildata = Object.assign([],item.data)
                   }
               }
                
            })
            this.getscoremoredialog = true
        },
        search(){
            var search = this.name;
            console.log(search)
            var newdate = [];
            if(search){
                if(search)
                 this.tableData.filter(item=>{
                     console.log(item)
                    if(item.COMMUNITY_NAME.indexOf(search) != -1){
                        newdate.push(item)
                    }
                })
            }else if (search == ''){
                console.log(this.tableData)
            }
            this.tableData = newdate
        },
         mohu() {
            var search = this.name;
            console.log(search)
            var newdate = [];
            if(search){
                if(search)
                 this.tableData.filter(item=>{
                     console.log(item)
                    if(item.COMMUNITY_NAME.indexOf(search) != -1){
                        newdate.push(item)
                    }
                })
            }else if (search == ''){
                console.log(this.tableData)
            }
            this.tableData = newdate
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible = true;
        },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(currentPage) {
            this.currentPage = currentPage;
            console.log(this.currentPage)
            // this.$set(this.query, 'pageIndex', val);
            // this.getData();
        },
        handleSizeChange(size){
            this.pagesize = size;
            console.log(this.pagesize)
        }
    }
}
</script>
<style scoped>
    .table{
        height: auto;
        border-collapse: collapse;
        border-spacing: 0;
        text-align:center;
        empty-cells: show;
        border: 1px solid #cbcbcb;
    }
    .table thead{
        background-color: #e0e0e0;
        border-bottom: 1px solid #cbcbcb;
        font-weight: 600;
    }
    .table tbody tr{
        border-bottom: 1px solid #cbcbcb;
    }
    .table td{
        padding:5px 0;
        border-left: 1px solid #cbcbcb;
        border-bottom: 1px solid #cbcbcb;
        border-width: 0 0 0 1px;
    }
    .p{
       display: none;
    }
</style>